package DAO;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import Beans.MozoBean;
import HibernateUtils.HibernateUtil;

public class HibernateMozoDAO {
	private static HibernateMozoDAO instancia;
	private static SessionFactory sf;
	private HibernateMozoDAO(){
		
	}
	
	public static HibernateMozoDAO getInstancia(){
		if(instancia==null){
			sf=HibernateUtil.getSessionFactory();
			instancia=new HibernateMozoDAO();
		}
		return instancia;
	}
	
	public void grabarMozo(MozoBean mozoB){
		Session session=sf.openSession();
		session.beginTransaction();
		session.save(mozoB);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}

	public MozoBean buscarMozo(MozoBean mozob) {
		Session session=sf.openSession();
		MozoBean mozo=(MozoBean) session.get(MozoBean.class, mozob.getIdEmpleado());
		session.close();
		return mozo;
	}
}
